import { Button, InputNumber } from 'antd';
import type React from 'react';
import { useState } from 'react';
import { DEFAULT_MAP_CENTER } from '@/config/constants';
import styles from '../../index.module.less';
import type { TestControlProps } from '../types';

const Index: React.FC<TestControlProps> = ({ maplessRef }) => {
  const [zoomLevel, setZoomLevel] = useState(13);

  const handleZoomChange = (value: number) => {
    setZoomLevel(value);
    maplessRef.current?.zoomTo(value);
  };

  function handleFlyToBeijing(): void {
    maplessRef.current?.flyTo({
      center: [116.404, 39.915],
      zoom: 15,
      speed: 1.2,
      curve: 1.42,
      essential: true,
    });
  }

  const handleFlyToChengdu = () => {
    maplessRef.current?.flyTo({
      center: [104.06, 30.67], // 成都的经纬度
      zoom: 12,
      speed: 1.5,
      curve: 1.5,
      essential: true,
    });
  };

  function handleFlyToGuangzhou(): void {
    maplessRef.current?.flyTo({
      center: DEFAULT_MAP_CENTER,
      zoom: 12,
      speed: 1.5,
      curve: 1.5,
      essential: true,
    });
  }

    function handleFlyToBonn(): void {
    maplessRef.current?.flyTo({
      center: [7.09, 50.73], // Bonn 的经纬度
      zoom: 11,
      speed: 1.5,
      curve: 1.5,
      essential: true
    });
  }

  return (
    <div className={styles.test}>
      <InputNumber
        min={1}
        max={20}
        step="0.5"
        style={{ width: '75px', pointerEvents: 'auto' }}
        value={zoomLevel}
        onChange={(e) => handleZoomChange(Number(e))}
      />
      <Button onClick={() => handleZoomChange(zoomLevel - 0.5)}>-</Button>
      <Button onClick={() => handleZoomChange(zoomLevel + 0.5)}>+</Button>
      <Button onClick={() => handleZoomChange(zoomLevel - 2)}>-2</Button>
      <Button onClick={() => handleZoomChange(zoomLevel + 2)}>+2</Button>
      <Button onClick={handleFlyToBeijing}>飞往北京</Button>
      <Button onClick={handleFlyToChengdu}>飞往成都</Button>
      <Button onClick={handleFlyToGuangzhou}>飞往广州</Button>
      <Button onClick={handleFlyToBonn}>飞往 Bonn</Button>
    </div>
  );
};

export default Index;
